//
//  HESettingAddressCell.m
//  HealthFamily
//
//  Created by 吴欧 on 2020/11/12.
//  Copyright © 2020 honglutec. All rights reserved.
//

#import "HESettingAddressCell.h"

@interface HESettingAddressCell ()

@property(nonatomic, strong) UILabel *titleLb;
@property(nonatomic, strong) UILabel *subLb;
@property(nonatomic, strong) UILabel *userInfoLb;
@property(nonatomic, strong) UILabel *defualtLb;
@property(nonatomic, strong) UIImageView *arrowView;

@property (nonatomic, assign) CGFloat defualtWidth;

@end

@implementation HESettingAddressCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        _defualtWidth = [@"默认" widthForFont:DYBlodFont(15)] + 10;

        [self initUI];
    }
    return self;
}

- (void)initUI {
    
    _arrowView = [UIImageView new];
    _arrowView.contentMode = UIViewContentModeScaleAspectFill;
    _arrowView.image = IMAGE_NAMED(@"go_gray");
    [self.contentView addSubview:_arrowView];
    
    [_arrowView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.right.equalTo(self.contentView).mas_offset(-15);
        make.width.mas_offset(8);
        make.height.mas_offset(12);
    }];
    
    _titleLb = [UILabel new];
    _titleLb.font = DYFont(15);
    _titleLb.text = @"-";
    _titleLb.textColor = CNavDargGrayColor;
    [self.contentView addSubview:_titleLb];
    
    _subLb = [UILabel new];
    _subLb.font = DYBlodFont(15);
    _subLb.text = @"-";
    _subLb.textColor = CNavLightBlackColor;
    _subLb.numberOfLines = 0;
    [self.contentView addSubview:_subLb];
    
    _userInfoLb = [UILabel new];
    _userInfoLb.font = DYFont(15);
    _userInfoLb.text = @"-";
    _userInfoLb.textColor = CNavLightBlackColor;
    [self.contentView addSubview:_userInfoLb];
    
    
    _defualtLb = [UILabel new];
    _defualtLb.font = DYBlodFont(15);
    _defualtLb.text = @"默认";
    _defualtLb.textColor = KWhiteColor;
    _defualtLb.backgroundColor = CPriceColor;
    _defualtLb.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:_defualtLb];
    
    
    [_titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).mas_offset(10);
        make.left.equalTo(self.contentView).mas_offset(15);
        make.right.equalTo(_arrowView.mas_left).mas_offset(-10);
    }];
    
    [_subLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_titleLb.mas_bottom).mas_offset(5);
        make.left.equalTo(_titleLb.mas_left);
        make.right.equalTo(_titleLb.mas_right);
    }];
     
    [_defualtLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_subLb.mas_bottom).mas_offset(5);
        make.left.equalTo(self.contentView).mas_offset(15);
        make.width.mas_equalTo(_defualtWidth);
    }];
    
    [_userInfoLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_subLb.mas_bottom).mas_offset(5);
        make.left.equalTo(self.contentView).mas_offset(15);
        make.right.equalTo(_titleLb.mas_right);
        make.bottom.equalTo(self.contentView).mas_offset(-10);
    }];
}

- (void)setModel:(HEReceiveAddressModel *)model {
    _model = model;
    
    _titleLb.text = model.KTitleString;
    _subLb.text = model.detailAddress;
    _userInfoLb.text = model.KUserInfo;
    
    if (model.defaultStatus) {
        _defualtLb.hidden = NO;
        [_userInfoLb mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).mas_offset(@(_defualtWidth + 20));
        }];
    }else {
        _defualtLb.hidden = YES;
        [_userInfoLb mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).mas_offset(15);
        }];
    }
}
    
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
